package org.swift.commons.deployer.services;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

public class EngineServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		InputStream fragmentStream = EngineServlet.class.getResourceAsStream(
				"/org/swift/commons/deployer/services/unitFragment.xml");
		String fragment = IOUtils.toString(fragmentStream);
		int engines = 10;
		try {
			engines = Integer.parseInt(req.getParameter("engines"));
		} catch (NumberFormatException nfe){
		}
		resp.setContentType("text/xml");
		resp.setStatus(200);
		PrintWriter writer = resp.getWriter();
		writer.write("<root>");
		for(int i = 0; i < engines; i++){
			writer.write(fragment);
		}
		writer.write("</root>");
		writer.flush();
		writer.close();
		
	}
}
